package com.loveto.service;

import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.loveto.common.ImageDownloader;
import com.loveto.common.JsonUtils;
import com.loveto.common.MyTouch;
import com.loveto.constant.LovetoConstant;
import com.loveto.constant.LovetoGiftAnims;
import com.loveto.model.GiftInfo;
import com.loveto.model.MemberInfo;

public class UserinfoViewMineActivity extends BaseActivity implements
View.OnClickListener, View.OnTouchListener {

	// 사용하는 변수들
	private Intent intentMoveToPage;
	private SharedPreferences pref;
	private Editor editor;
	private Handler myHandler = new Handler();
	private ProgressDialog progressDialog;
	private String memberid;
	private String my_gender;
	private int my_point;
	private int newMessageCnt = 0;
	private int not_select_winner_tournamentID = 0;
	private int not_view_winner_tournamentID = 0;
	private MemberInfo memberInfo;
	
	private List<AnimationDrawable> giftAnimList;
	private LovetoGiftAnims giftAnims = new LovetoGiftAnims();
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loveto_userinfo_view_mine);
		
		//변수 선언
		progressDialog = new ProgressDialog(this);
		
		//로컬에서 정보 받아오기
		pref = getSharedPreferences("userInfo", Activity.MODE_PRIVATE);
		editor = pref.edit();
		memberid = pref.getString("memberid", "");
		my_gender = pref.getString("gender", "");
		my_point = pref.getInt("point", 0);
		
		giftAnimList = new ArrayList<AnimationDrawable>();
		
		//배경 성별에 따른 처리
		String strGender = "여성";
		TextView v_userinfo_id = (TextView) findViewById(R.id.userinfo_id);
		v_userinfo_id.setText(memberid);
		if ("M".equals(my_gender)) {
			strGender = "남성";
			RelativeLayout v_userinfo_bg = (RelativeLayout) findViewById(R.id.userinfo_bg);
			v_userinfo_bg.setBackgroundResource(R.drawable.bg_user_man);
			v_userinfo_id.setTextColor(getResources().getColor(R.color.textMan));
			((ImageView)findViewById(R.id.photo_round)).setImageResource(R.drawable.bg_photo_round_man);
		}
		TextView v_userinfo_gender = (TextView) findViewById(R.id.userinfo_gender);
		v_userinfo_gender.setText(strGender);
		
		// 터치 리스너 달기 // 버튼
		RelativeLayout footer01 = (RelativeLayout) findViewById(R.id.btn_footer01);
		footer01.setOnTouchListener(this);
		RelativeLayout footer02 = (RelativeLayout) findViewById(R.id.btn_footer02);
		footer02.setOnTouchListener(this);
		RelativeLayout footer03 = (RelativeLayout) findViewById(R.id.btn_footer03);
		footer03.setOnTouchListener(this);
		RelativeLayout footer05 = (RelativeLayout) findViewById(R.id.btn_footer05);
		footer05.setOnTouchListener(this);
		RelativeLayout v_btn_edit_profile = (RelativeLayout) findViewById(R.id.btn_edit_profile);
		v_btn_edit_profile.setOnClickListener(this);
		ImageView v_userinfo_photo = (ImageView) findViewById(R.id.userinfo_photo);
		v_userinfo_photo.setOnClickListener(this);
		
		//선물 목록 가져오기
		
		if (isNetworkAvailable()) {
			getGiftInfo();
			getNewMessage();
		}
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_edit_profile:
			Log.d("tag","클릭했다");
			intentMoveToPage = new Intent(UserinfoViewMineActivity.this,UserinfoEditMainActivity.class);
			startActivity(intentMoveToPage);
			break;
		case R.id.btn_show_album:
			intentMoveToPage = new Intent(UserinfoViewMineActivity.this,UserinfoViewAlbumMineActivity.class); 
			startActivity(intentMoveToPage);
			break;
		case R.id.userinfo_photo:
			intentMoveToPage = new Intent(UserinfoViewMineActivity.this,UserinfoViewAlbumMineActivity.class); 
			startActivity(intentMoveToPage);
			break;
		}
		
	}
	

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		//유저의 나머지 정보 세팅 , 다른 화면갔다가 finish 로 백했을 때도 리프레시 됨.
		if (isNetworkAvailableAndNotice()) {
			getUserInfo();
		}
		
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btn_footer01:
			if (event.getAction() == MotionEvent.ACTION_DOWN){
				v.setBackgroundResource(R.drawable.btn_footer_touch);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP){
				if (MyTouch.checkClick(v, event)) { //손을 땐 좌표로 클릭 여부 판단
					gotoActive(LovotoMainActivity.class, v, R.drawable.btn_footer_unselected);
				} else {
					v.setBackgroundResource(R.drawable.btn_footer_unselected);
				}
			}
			break;
		case R.id.btn_footer02:
			if (event.getAction() == MotionEvent.ACTION_DOWN){
				v.setBackgroundResource(R.drawable.btn_footer_touch);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP){
				if (MyTouch.checkClick(v, event)) { //손을 땐 좌표로 클릭 여부 판단
					gotoActive(JoinedTournamentListActivity.class, v, R.drawable.btn_footer_unselected);
				} else {
					v.setBackgroundResource(R.drawable.btn_footer_unselected);
				}
			}
			break;
		case R.id.btn_footer03:
			if (event.getAction() == MotionEvent.ACTION_DOWN){
				v.setBackgroundResource(R.drawable.btn_footer_touch);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP){
				if (MyTouch.checkClick(v, event)) { //손을 땐 좌표로 클릭 여부 판단
					gotoActive(MessageMainActivity.class, v, R.drawable.btn_footer_unselected);
				} else {
					v.setBackgroundResource(R.drawable.btn_footer_unselected);
				}
			}
			break;
		case R.id.btn_footer04:
			if (event.getAction() == MotionEvent.ACTION_DOWN){
				v.setBackgroundResource(R.drawable.btn_footer_touch);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP){
				if (MyTouch.checkClick(v, event)) { //손을 땐 좌표로 클릭 여부 판단
					gotoActive(UserinfoViewMineActivity.class, v, R.drawable.btn_footer_unselected);
				} else {
					v.setBackgroundResource(R.drawable.btn_footer_unselected);
				}
			}
			break;
		case R.id.btn_footer05:
			if (event.getAction() == MotionEvent.ACTION_DOWN){
				v.setBackgroundResource(R.drawable.btn_footer_touch);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP){
				if (MyTouch.checkClick(v, event)) { //손을 땐 좌표로 클릭 여부 판단
					gotoActive(SetupMainActivity.class, v, R.drawable.btn_footer_unselected);
				} else {
					v.setBackgroundResource(R.drawable.btn_footer_unselected);
				}
			}
			break;
		}
		return true;
	}

	//유저 정보를 서버에서 받아옴
	private void getUserInfo() {
		progressDialog.setMessage("정보를 불러오고있습니다.");
		progressDialog.show();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Log.d("tag", "Start getUserInfo()");
					String jsonText = JsonUtils
							.getStringFromUrl(LovetoConstant.USERINFO_MINE_URL
									+ "?memberid=" + memberid);
					Log.d("tag", jsonText);
					// 원격에서 읽어온 데이터로 JSON 객체 생성
					try {
						JSONArray jsonArray = new JSONArray(jsonText);
						JSONObject object = jsonArray.getJSONObject(0);

						memberInfo = new MemberInfo(object
								.getInt("innocent_cnt"), object
								.getInt("sexy_cnt"), object.getInt("cuty_cnt"),
								object.getInt("intelligent_cnt"), object
										.getInt("follower_cnt"), object
										.getInt("point"), object
										.getString("introduce"), object
										.getString("age"), object
										.getString("local"), object
										.getString("local_detail"), object
										.getString("job"), object
										.getString("height"), object
										.getString("characters"), object
										.getString("look"), object
										.getString("hobby"), object
										.getString("favorite"), object
										.getString("idealtype"), object
										.getString("photo_url1"), object
										.getString("photo_url2"), object
										.getString("photo_url3"), object
										.getString("photo_url4"));

						// 사진 URL 저장 (앨범에서 수정하기 위한)
						editor.putString("photo_url1",object.getString("photo_url1"));
						editor.putString("photo_url2",object.getString("photo_url2"));
						editor.putString("photo_url3",object.getString("photo_url3"));
						editor.putString("photo_url4",object.getString("photo_url4"));
						editor.commit();

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace(); 
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				} finally {
					myHandler.post(new Runnable() {
						@Override
						public void run() {
							makeUserInfoLayout(memberInfo);
							progressDialog.dismiss();
						}
					});
					Log.d("tag", "End getUserInfo()");
				}
			}
		}).start();
	}
	
	//화면 전환 시켜주기
	private void gotoActive(Class<?> class1,View v,int d) {
		intentMoveToPage = new Intent(UserinfoViewMineActivity.this,
				class1);
		startActivity(intentMoveToPage);
		v.setBackgroundResource(d);
	}
	
	
	
	//애니메이션은 윈도우에 포커스가 간 뒤에 스타트 시켜야 제대로 나옴.
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		
		for (int i=0;i<giftAnimList.size();i++) {
			giftAnimList.get(i).start();
		}
		
	    super.onWindowFocusChanged(hasFocus);
	}
	
	private void getGiftInfo() {
		Runnable runnable = new Runnable(){
			@Override
			public void run() {
				//UI 를 건들기 때문에 핸들러 사용.
				myHandler.post(new Runnable() {
					@Override
					public void run() {
							try {
								Log.d("tag", "getGiftInfo() start");
								String jsonText = JsonUtils.getStringFromUrl(LovetoConstant.GIFT_OWN_LIST + "?memberid=" + memberid);
								//Log.d("tag", "jsonText : " + jsonText);
								try {
									JSONArray jsonArray = new JSONArray(jsonText);
									for (int i = 0; i < jsonArray.length();i++) {
										JSONObject object = jsonArray.getJSONObject(i);
										GiftInfo giftInfo = new GiftInfo(object.getInt("giftid"), object.getString("category"), "", object.getString("size"), object.getString("name"), object.getInt("price"), 0, "");
										makeGiftLayout(giftInfo, object.getInt("own_cnt"));
									}
								} catch (JSONException e) {
									e.printStackTrace();
									Log.d("tag", "getGiftInfo() error, " + e.getMessage());
								}
							} catch (UnsupportedEncodingException e) {
								e.printStackTrace();
								Log.d("tag", "getGiftInfo() error, " + e.getMessage());
							} finally {
							}
						}
				});
			}
		};
		new Thread(runnable).start();
	}
	
	private void makeGiftLayout(GiftInfo giftInfo,int giftOwnCnt) {
		
		//값 받아오기
		int giftid = giftInfo.getGiftid();
		String size = giftInfo.getSize();
		String name = giftInfo.getName();
		
		//그림 넣을 위치
		LinearLayout v_giftlist = (LinearLayout) findViewById(R.id.area_gift_list);
		RelativeLayout v_area_gift;
		if ("L".equals(size)) {
			v_area_gift = (RelativeLayout) getLayoutInflater().inflate(R.layout.loveto_gift_list_large, null);
		} else if ("M".equals(size)) {
			v_area_gift = (RelativeLayout) getLayoutInflater().inflate(R.layout.loveto_gift_list_medium, null);
		} else {
			v_area_gift = (RelativeLayout) getLayoutInflater().inflate(R.layout.loveto_gift_list_small, null);
		}
		ImageView image = (ImageView)v_area_gift.findViewById(R.id.gift_img);
		
		//그림에 애니메이션을 넣을지 그림을 넣을지 판단
		if (giftAnims.getGiftAnimMap().containsKey(giftid)) { 
			//로컬에 선물 아이디에 대한 애니메이션 리소스가 있으면
			image.setBackgroundResource(giftAnims.getGiftAnimMap().get(giftid)); //애니메이션 지정
			giftAnimList.add((AnimationDrawable)image.getBackground()); //애니메이션 배열에 추가 (나중에 한번에 start 하기 위해)
		} else {
			//현재 버전에 선물에 대한 애니메이션 리소스가 없으면 FTP 의 1장짜리 이미지로 대체함
			String url = LovetoConstant.GIFT_IMAGE_URL + giftid + ".png";
			Log.d("tag","선물 url: " + url);
			ImageDownloader imageDownloader = new ImageDownloader();
			imageDownloader.download(url, image);
		}
		
		//이름 달기
		((TextView)v_area_gift.findViewById(R.id.text_price)).setText(name);
		//개수 달기
		((TextView)v_area_gift.findViewById(R.id.text_point)).setText(giftOwnCnt+"개");
		//가격 아이콘 숨기기
		((ImageView)v_area_gift.findViewById(R.id.icon_gift_price_id)).setVisibility(ImageView.GONE);
		
		//선물 뷰에 추가하기
		v_giftlist.addView(v_area_gift);
	}
	
	private void getNewMessage() {
		
		//비로그인 시 실행하지 않음.
		if ("".equals(memberid)) {
			return;
		}
		
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				
				try {
					
					StringBuffer URL = new StringBuffer();
					URL.append(LovetoConstant.MESSAGE_CHECK_NEW_URL);
					URL.append("?memberid=").append(memberid);
					Log.d("tag", "URL: " + URL.toString());
					//서버에서 정보 받아오기
					String jsonText = JsonUtils.getStringFromUrl(URL.toString());
					Log.d("tag", "jsonText: " + jsonText);
					JSONObject getObject = new JSONObject(jsonText);
					newMessageCnt = getObject.getInt("new_cnt");
					Log.d("tag", "newMessageCnt: " + newMessageCnt);
					not_select_winner_tournamentID = getObject.getInt("not_select_winner_tournamentID");
					Log.d("tag", "not_select_winner_tournamentID: " + not_select_winner_tournamentID);
					not_view_winner_tournamentID = getObject.getInt("not_view_winner_tournamentID");
					Log.d("tag", "not_view_winner_tournamentID: " + not_view_winner_tournamentID);
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
					Log.d("tag", "Get Json error : " + e.toString());
				} catch (JSONException e) {
					e.printStackTrace();
					Log.d("tag", "Get Json error : " + e.toString());
				} finally {
					// 풋터에 새 쪽지 개수 보여주기
					myHandler.post(new Runnable() {
						@Override
						public void run() {
							//풋터에 새로 받은 쪽지 개수 표시하기
							TextView vNewMsg = (TextView) findViewById(R.id.message_new_cnt);
							if (newMessageCnt !=0) {
								vNewMsg.setText("" + newMessageCnt);
								vNewMsg.setVisibility(TextView.VISIBLE);
							}
							if (not_select_winner_tournamentID != 0 || not_view_winner_tournamentID != 0) {
								showSimpleAlertForSelectOrViewWinner();
							}
						}
					});
				}
				Log.d("tag", "sendTalkMessage() end");
			}
		};
		new Thread(runnable).start();
	}

	private void showSimpleAlertForSelectOrViewWinner() {
		String title;
		String msg;
		if (not_select_winner_tournamentID != 0) {
			title = "토너먼트 주최완료!";
			msg = "주최 한 토너먼트의 마감시간이 완료되어 우승자를 결정해야합니다. 이동하시겠습니까?";
		} else {
			title = "우승자 결정완료!";
			msg = "참여 한 토너먼트의 우승자 결정이 완료되었습니다. 결과를 보기위해 이동하시겠습니까?";
		}
		new AlertDialog.Builder(this)
		.setTitle(title)
		.setMessage(msg)
		.setPositiveButton("이동", new DialogInterface.OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				if (isNetworkAvailableAndNotice()) {
					dialog.dismiss();
					int gotoTournamentID = 0;
					if (not_select_winner_tournamentID != 0) {
						gotoTournamentID = not_select_winner_tournamentID;
					} else {
						gotoTournamentID = not_view_winner_tournamentID;
					}
					Intent intent = new Intent(UserinfoViewMineActivity.this, InfoTournamentActivity.class);
					intent.putExtra("tournamentID", "" + gotoTournamentID);
					startActivity(intent);
					
				}
			}
		})
		.setNegativeButton("취소", new DialogInterface.OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
			}
		}).show();
		
	}
	
	private void makeUserInfoLayout (MemberInfo memberInfo) {
		
		int innocent_cnt = memberInfo.getInnocent_cnt();
		int sexy_cnt = memberInfo.getSexy_cnt();
		int cuty_cnt = memberInfo.getCuty_cnt();
		int intelligent_cnt = memberInfo.getInnocent_cnt();
		int popularity_total = innocent_cnt + sexy_cnt + cuty_cnt + intelligent_cnt;
		TextView v_userinfo_popularity = (TextView) findViewById(R.id.userinfo_popularity);
		v_userinfo_popularity.setText("인기도 : " + popularity_total);
		TextView v_userinfo_popularity_detail = (TextView) findViewById(R.id.userinfo_popularity_detail);
		v_userinfo_popularity_detail.setText("(청순" + innocent_cnt + "/섹시" + sexy_cnt  + "/큐티" +  cuty_cnt +  "/지적" + intelligent_cnt + ")");
		TextView v_userinfo_likeusers = (TextView) findViewById(R.id.userinfo_likeusers);
		v_userinfo_likeusers.setText("호감 갖는 이 : " + memberInfo.getFollower_cnt() + "명");
		TextView v_userinfo_introduce = (TextView) findViewById(R.id.userinfo_introduce);
		String introduce = memberInfo.getIntroduce();
		if ("null".equals(introduce)||"".equals(introduce)) {
			v_userinfo_introduce.setText("인사말 :");
		} else {
			v_userinfo_introduce.setText("인사말 : " + introduce);
		}
		String age = memberInfo.getAge();
		TextView v_userinfo_age = (TextView) findViewById(R.id.userinfo_age);
		if ("null".equals(age)||"".equals(age)) {
			v_userinfo_age.setText("미설정");
			v_userinfo_age.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_age.setText(age);
			v_userinfo_age.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String local = memberInfo.getLocal();
		String local_detail = memberInfo.getLocal_detail();
		TextView v_userinfo_local = (TextView) findViewById(R.id.userinfo_local);
		if ("null".equals(local)||"".equals(local)) {
			v_userinfo_local.setText("미설정");
			v_userinfo_local.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_local.setText(local + " " + local_detail);
			v_userinfo_local.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String job = memberInfo.getJob();
		TextView v_userinfo_job = (TextView) findViewById(R.id.userinfo_job);
		if ("null".equals(job)||"".equals(job)) {
			v_userinfo_job.setText("미설정");
			v_userinfo_job.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_job.setText(job);
			v_userinfo_job.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String height = memberInfo.getHeight();
		TextView v_userinfo_height = (TextView) findViewById(R.id.userinfo_height);
		if ("null".equals(height)||"".equals(height)) {
			v_userinfo_height.setText("미설정");
			v_userinfo_height.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_height.setText(height);
			v_userinfo_height.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String characters = memberInfo.getCharacters();
		TextView v_userinfo_characters = (TextView) findViewById(R.id.userinfo_characters);
		if ("null".equals(characters)||"".equals(characters)) {
			v_userinfo_characters.setText("미설정");
			v_userinfo_characters.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_characters.setText(characters);
			v_userinfo_characters.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String look = memberInfo.getLook();
		TextView v_userinfo_look = (TextView) findViewById(R.id.userinfo_look);
		if ("null".equals(look)||"".equals(look)) {
			v_userinfo_look.setText("미설정");
			v_userinfo_look.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_look.setText(look);
			v_userinfo_look.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String hobby = memberInfo.getHobby();
		TextView v_userinfo_hobby = (TextView) findViewById(R.id.userinfo_hobby);
		if ("null".equals(hobby)||"".equals(hobby)) {
			v_userinfo_hobby.setText("미설정");
			v_userinfo_hobby.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_hobby.setText(hobby);
			v_userinfo_hobby.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String favorite = memberInfo.getFavorite();
		TextView v_userinfo_favorite = (TextView) findViewById(R.id.userinfo_favorite);
		if ("null".equals(favorite)||"".equals(favorite)) {
			v_userinfo_favorite.setText("미설정");
			v_userinfo_favorite.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_favorite.setText(favorite);
			v_userinfo_favorite.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		String idealtype = memberInfo.getIdealtype();
		TextView v_userinfo_idealtype = (TextView) findViewById(R.id.userinfo_idealtype);
		if ("null".equals(idealtype)||"".equals(idealtype)) {
			v_userinfo_idealtype.setText("미설정");
			v_userinfo_idealtype.setTextColor(getResources().getColor(R.color.textGray));
		} else {
			v_userinfo_idealtype.setText(idealtype);
			v_userinfo_idealtype.setTextColor(getResources().getColor(R.color.textNormalBlack));
		}
		
		//클로버 포인트 가져오기
		TextView v_text_point = (TextView)findViewById(R.id.text_point);
		DecimalFormat df = new DecimalFormat("#,##0");
		int point = memberInfo.getPoint();
		v_text_point.setText("" + df.format((double)point));
		
		if (my_point != point) { //만약 DB에서 받아온 포인트값이 로컬의 값과 다르면 교체
			Log.d("tag","로컬의 포인트정보가 DB와 다릅니다.");
			editor.putInt("point", point);
			editor.commit();
		}
		
		//사진 변경
		String photo_url1 = memberInfo.getPhoto_url1();
		if ("Y".equals(photo_url1)) {
			String url = LovetoConstant.PHOTO_THUMB_URL + memberid + ".jpg";
			ImageDownloader imageDownloader = new ImageDownloader();
			ImageView imgView = (ImageView) findViewById(R.id.userinfo_photo);
			imageDownloader.download(url, imgView);
		} else if ("M".equals(my_gender)) {
			((ImageView)findViewById(R.id.userinfo_photo)).setImageResource(R.drawable.photo_blank_man);
		} else {
			((ImageView)findViewById(R.id.userinfo_photo)).setImageResource(R.drawable.photo_blank_woman);
		}
		
	}
}
